package com.manage.modules.controller;

import java.util.List;
import java.util.Arrays;

import com.alibaba.fastjson.JSONObject;
import com.manage.modules.utils.DateUtil;
import com.manage.modules.utils.RandomUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.common.annotation.Log;
import com.manage.common.core.controller.BaseController;
import com.manage.common.core.domain.AjaxResult;
import com.manage.common.enums.BusinessType;
import com.manage.modules.vo.TBaseServiceVo;
import com.manage.modules.bo.TBaseServiceQueryBo;
import com.manage.modules.bo.TBaseServiceAddBo;
import com.manage.modules.bo.TBaseServiceEditBo;
import com.manage.modules.service.ITBaseServiceService;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 维护单管理Controller
 *
 * @author wx
 * @date 2021-08-26
 */
@Api(value = "维护单管理控制器", tags = {"维护单管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/modules/serviceInfo")
public class TBaseServiceController extends BaseController {

    private final ITBaseServiceService iTBaseServiceService;

    /**
     * 获取维护单编号
     */
    @GetMapping("/getServiceCode")
    public AjaxResult getServiceCode() {
        JSONObject data = new JSONObject();
        data.put("serviceCode", "service_" + DateUtil.getNowDate() + RandomUtil.getRandomIntInRange(10000, 99999));
        return AjaxResult.success(data);
    }

    /**
     * 查询维护单管理列表
     */
    @ApiOperation("查询维护单管理列表")
    @PreAuthorize("@ss.hasPermi('modules:serviceInfo:list')")
    @GetMapping("/list")
    public TableDataInfo<TBaseServiceVo> list(TBaseServiceQueryBo bo) {
        startPage();
        List<TBaseServiceVo> list = iTBaseServiceService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出维护单管理列表
     */
    @ApiOperation("导出维护单管理列表")
    @PreAuthorize("@ss.hasPermi('modules:serviceInfo:export')")
    @Log(title = "维护单管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TBaseServiceVo> export(TBaseServiceQueryBo bo) {
        List<TBaseServiceVo> list = iTBaseServiceService.queryList(bo);
        ExcelUtil<TBaseServiceVo> util = new ExcelUtil<TBaseServiceVo>(TBaseServiceVo.class);
        return util.exportExcel(list, "维护单管理");
    }

    /**
     * 获取维护单管理详细信息
     */
    @ApiOperation("获取维护单管理详细信息")
    @PreAuthorize("@ss.hasPermi('modules:serviceInfo:query')")
    @GetMapping("/{serviceId}")
    public AjaxResult<TBaseServiceVo> getInfo(@PathVariable("serviceId") Long serviceId) {
        return AjaxResult.success(iTBaseServiceService.queryById(serviceId));
    }

    /**
     * 新增维护单管理
     */
    @ApiOperation("新增维护单管理")
    @PreAuthorize("@ss.hasPermi('modules:serviceInfo:add')")
    @Log(title = "维护单管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TBaseServiceAddBo bo) {
        return toAjax(iTBaseServiceService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改维护单管理
     */
    @ApiOperation("修改维护单管理")
    @PreAuthorize("@ss.hasPermi('modules:serviceInfo:edit')")
    @Log(title = "维护单管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TBaseServiceEditBo bo) {
        return toAjax(iTBaseServiceService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除维护单管理
     */
    @ApiOperation("删除维护单管理")
    @PreAuthorize("@ss.hasPermi('modules:serviceInfo:remove')")
    @Log(title = "维护单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serviceIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] serviceIds) {
        return toAjax(iTBaseServiceService.deleteWithValidByIds(Arrays.asList(serviceIds), true) ? 1 : 0);
    }
}
